#include<bits/stdc++.h>
using namespace std;
int n,cnt,thrown=0,fir;
inline int read(){
	int x=0,c=getchar();
	for(;48>c || c>57;c=getchar());
	for(;48<=c && c<=57;c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x;
}
struct block{
	int l,r,last,next,type;
}a[200005];
int main(){
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	n=read();
	int p,lp=2;
	for(int i=1;i<=n;++i){
		p=read();
		if(lp==2){
			a[++cnt].l=i;
			a[cnt].type=p;
			fir=cnt;
		}
		else if(lp!=p){
			a[cnt].r=i-1;
			a[cnt].next=++cnt;
			a[cnt].l=i,a[cnt].last=cnt-1,a[cnt].type=p;
		}
		lp=p;
	}
	a[cnt].r=n;
	int pp;
	while(thrown<n){
		if(a[fir].r-a[fir].l==0){
			printf("%d ",a[fir].l);
			++thrown;
			fir=a[fir].next;
			a[fir].last=0;
		}
		for(int pos=fir;pos!=0;pos=a[pos].next){
			if(a[pos].r==a[pos].l){
				printf("%d ",a[pos].l);
				++thrown;
				if(a[pos].next!=0 && a[a[pos].last].type==a[a[pos].next].type){
					pp=a[pos].last;
					a[pp].r=a[a[pos].next].r;
					a[pp].next=a[a[pos].next].next;
				}
				else if(a[pos].next==0){
					a[a[pos].last].next==0;
				}
			}
			else{
				printf("%d ",a[pos].l);
				++a[pos].l,++thrown;
			}
		}
		puts("");
	}
	return 0;
}

